package com.itheima.controller;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.empQueryParam;
import com.itheima.service.ClazzService;
import com.itheima.service.impl.ClazzServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    //班级列表查询
    @GetMapping()
    public Result ClazzList(empQueryParam empQueryParam){

      PageResult<Clazz> pageResult= clazzService.ClazzList(empQueryParam);
      return Result.success(pageResult);
    }

    //删除班级
    @DeleteMapping("/{id}")
    public Result deleteClazz(@PathVariable Integer id){
        clazzService.deleteClazz(id);
        return Result.success();
    }

    //添加班级
    @PostMapping()
    public Result addClazz(@RequestBody Clazz clazz){
        clazzService.addClazz(clazz);
        return Result.success();
    }

    //查询回显
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        Clazz clazz=clazzService.getInfo(id);
        return Result.success(clazz);
    }

    //修改班级
    @PutMapping()
    public Result update(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return Result.success();
    }
    //查询所有班级
    @GetMapping("list")
    public Result getAll(){
      List<Clazz> list= clazzService.getAll();
      return Result.success(list);
    }
}
